package com.unfbx.chatgpt.controller;

import com.unfbx.chatgpt.entity.chat.Message;
import com.unfbx.chatgpt.service.ChatService;
import com.unfbx.chatgpt.utils.R;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.servlet.ModelAndView;

import java.util.List;

@RestController
@RequestMapping("/chat")
public class ChatController {
    @Autowired
    private ChatService service;

    @GetMapping("/index")
    private ModelAndView seach(){
        ModelAndView view = new ModelAndView("chatindex");
        return view;
    }

    @PostMapping("/chat")
    private R answer(@RequestBody String message){

        List answer = service.getAnswer(message);

        boolean b = answer != null;
        return new R(b,answer.get(0),b?"查询成功":"查询失败",b?200:500);
    }


}
